package cfgs.gestudent.dao.tipusObligacio;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.ResourceBundle;
import java.sql.Statement;

import javax.swing.JOptionPane;

import cfgs.gestudent.dao.connexio.ConnexioDB;
import cfgs.gestudent.preferencies.ConfiguracionsIdiomes;

public class ObtenirTipusObligacio {
	
	private ConfiguracionsIdiomes idioma = new ConfiguracionsIdiomes();
	private ResourceBundle rb = idioma.getIdioma();
	
	public ArrayList<String> llistesComboBox(){
		ArrayList<String> llista = new ArrayList<>();
		
		Connection connexio = ConnexioDB.getConnexio();
		ResultSet rs = null;
		Statement st = null;
		
		String query = "SELECT Nom FROM TIPUS_OBLIGACIO";
		
		try {
			st=connexio.createStatement();
			rs = st.executeQuery(query);
			while(rs.next()){
				String nom = rs.getString("Nom");
				llista.add(nom);
			}
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, rb.getString("missatgeErrorStatement")+"\n "+e, rb.getString("titolErrorStatement"), JOptionPane.ERROR_MESSAGE);
		}finally{
			try {
				connexio.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				JOptionPane.showMessageDialog(null, rb.getString("missatgeErrorTancarConnexio")+"\n "+e, rb.getString("titolErrorTancarConnexio"), JOptionPane.ERROR_MESSAGE);
			}
		}
		
		
		return llista;
	}

}
